package com.bjpowernode.boss.mvc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjpowernode.boss.convert.UserConfigConvert;
import com.bjpowernode.boss.mvc.models.query.UserConfigQuery;
import com.bjpowernode.boss.mvc.models.response.AjaxResult;
import com.bjpowernode.boss.mvc.models.vo.UserPayConfigVo;
import com.bjpowernode.boss.mvc.service.UserPaymentConfigService;
import com.bjpowernode.boss.persist.domain.UserPayConfig;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserPaymentConfigController {

    @Resource
    private UserPaymentConfigService userPaymentConfigService;

    @Resource
    private UserConfigConvert userConfigConvert;

    @GetMapping("/config/product/pageList/{pageNo}")
    public AjaxResult productPageList(@PathVariable int pageNo) {

        Page<UserPayConfig> userPayConfigPage = userPaymentConfigService.loadUserPayProductPage(pageNo);

        Map<String, Object> result = new HashMap<>();

        List<UserPayConfig> records = userPayConfigPage.getRecords();
        List<UserPayConfigVo> list = userConfigConvert.userPayConfigListToVoList(records);

        long total = userPayConfigPage.getTotal();
        result.put("total", total);
        result.put("list", list);
        return AjaxResult.OK(result);
    }

    @PostMapping("/config/user/addProduct")
    public AjaxResult addProduct(@RequestBody UserConfigQuery userConfigQuery) {

        userPaymentConfigService.addProduct(userConfigQuery);
        return AjaxResult.OK();

    }

    //删除用户支付配置
    @DeleteMapping("/config/product/{userNo}/{productCode}")
    public AjaxResult deleteUserProductConfig(@PathVariable String userNo, @PathVariable String productCode) {

        userPaymentConfigService.deleteUserProductConfig(userNo, productCode);
        return AjaxResult.OK();

    }

}
